package com.jet.chat.client;
import java.io.BufferedReader;

import com.jet.chat.exception.ChatExceptionMessageRead;
import com.jet.chat.service.ChatMessage;
import com.jet.chat.service.ChatMessageService;


public class ChatClientServerReader implements Runnable {
	private BufferedReader reader;
	
	public ChatClientServerReader(BufferedReader reader) {
		this.reader = reader;
	}

	@Override
	public void run() {
		ChatMessage chatMessage = null;
		try {
			while ((chatMessage = new ChatMessage(reader)).getMessage() != null) {
				if (chatMessage.getMessage().equals("/q")) {
					System.exit(0);
				} else {
					System.out.println(chatMessage.getMessage());
				}
			}
		} catch (ChatExceptionMessageRead e) {
			System.out.println("server shutdown");
			System.exit(0);
			//e.printStackTrace();
		}
	}

}
